package types

import (
	bytes "bytes"
	database_sql_driver "database/sql/driver"
	errors "errors"

	github_com_go_courier_enumeration "github.com/go-courier/enumeration"
)

var InvalidPlatformProtocol = errors.New("invalid PlatformProtocol type")

func ParsePlatformProtocolFromLabelString(s string) (PlatformProtocol, error) {
	switch s {
	case "":
		return PLATFORM_PROTOCOL_UNKNOWN, nil
	case "http":
		return PLATFORM_PROTOCOL__HTTP, nil
	case "https":
		return PLATFORM_PROTOCOL__HTTPS, nil
	}
	return PLATFORM_PROTOCOL_UNKNOWN, InvalidPlatformProtocol
}

func (v PlatformProtocol) String() string {
	switch v {
	case PLATFORM_PROTOCOL_UNKNOWN:
		return ""
	case PLATFORM_PROTOCOL__HTTP:
		return "HTTP"
	case PLATFORM_PROTOCOL__HTTPS:
		return "HTTPS"
	}
	return "UNKNOWN"
}

func ParsePlatformProtocolFromString(s string) (PlatformProtocol, error) {
	switch s {
	case "":
		return PLATFORM_PROTOCOL_UNKNOWN, nil
	case "HTTP":
		return PLATFORM_PROTOCOL__HTTP, nil
	case "HTTPS":
		return PLATFORM_PROTOCOL__HTTPS, nil
	}
	return PLATFORM_PROTOCOL_UNKNOWN, InvalidPlatformProtocol
}

func (v PlatformProtocol) Label() string {
	switch v {
	case PLATFORM_PROTOCOL_UNKNOWN:
		return ""
	case PLATFORM_PROTOCOL__HTTP:
		return "http"
	case PLATFORM_PROTOCOL__HTTPS:
		return "https"
	}
	return "UNKNOWN"
}

func (v PlatformProtocol) Int() int {
	return int(v)
}

func (PlatformProtocol) TypeName() string {
	return "demo/device-hub/constants/types.PlatformProtocol"
}

func (PlatformProtocol) ConstValues() []github_com_go_courier_enumeration.IntStringerEnum {
	return []github_com_go_courier_enumeration.IntStringerEnum{PLATFORM_PROTOCOL__HTTP, PLATFORM_PROTOCOL__HTTPS}
}

func (v PlatformProtocol) MarshalText() ([]byte, error) {
	str := v.String()
	if str == "UNKNOWN" {
		return nil, InvalidPlatformProtocol
	}
	return []byte(str), nil
}

func (v *PlatformProtocol) UnmarshalText(data []byte) (err error) {
	*v, err = ParsePlatformProtocolFromString(string(bytes.ToUpper(data)))
	return
}

func (v PlatformProtocol) Value() (database_sql_driver.Value, error) {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}
	return int64(v) + int64(offset), nil
}

func (v *PlatformProtocol) Scan(src interface{}) error {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}

	i, err := github_com_go_courier_enumeration.ScanIntEnumStringer(src, offset)
	if err != nil {
		return err
	}
	*v = PlatformProtocol(i)
	return nil
}
